﻿@model OnlineViewModel

<script type="text/javascript">
	function loadStepData() {
		if (window.OnlineContent.Name) {
			$("#videoName").text(window.OnlineContent.Name);
		}
	}
	function addline() {

	    var x = document.getElementById('emTable').insertRow(0);
	    var y = x.insertCell(0);
	    var z = x.insertCell(1);
	    y.innerHTML = '<input class="em-add-mail" type="email"></input>';
	    z.innerHTML = '<a href="#" class="em-rm-link" onclick="return rmline(this);">Х</a>';
	    return false;

	}
	function rmline(r) {
	    var i = r.parentNode.parentNode.rowIndex;
	    document.getElementById('emTable').deleteRow(i)
	    return false;
	}
	function rmall(t) {

	}
	function getRows(t) {
	    var r = document.getElementById(t);
	    var trList = r.getElementsByTagName('input');
	    var all = "";
	    for (var i = 0; i < trList.length; i++) {
	        var vl = trList[i].value;
	        if (vl && vl != "") {
	            if (all != "")
	                all = all + "&";
	            all = all + trList[i].value;
	        }
	    }
	    return all;
	}
	function readyEmails(t) {
	    var lst = getRows(t);
	    if (lst && lst.trim() != "") {
	        var txt = document.getElementById("emText");
           // alert(txt)
	        if (txt && txt.value != "") {
	            var retRes = false;
	            $.ajax({
	                type: "POST",
	                url: window.MAIN_WEB_PATH + "Ajax/SendInvitations",
	                dataType: "json",
	                async: false,
	                data: {
	                    text: txt.value,
	                    toList: lst
	                },
	                success: function (data, textStatus, jqXHR) {
	                   
	                    var r1 = document.getElementById('emBlockWz');
	                    var r2 = document.getElementById('emOkWz');
	                    if (r2)
	                        r2.style.display = "block";
	                    if (r1)
	                        r1.style.display = "none";
	                    return;
	                }
		});
        return retRes;

	        }
	    }
	}

</script>
<form>    
    <h3>@Html.GetGlobalResource("OnlineWizard", "Congratulations")</h3>
	<div>@Html.GetGlobalResource("OnlineWizard", "CongratulationsPart1")<label id="videoName"></label>@Html.GetGlobalResource("OnlineWizard", "CongratulationsPart2")</div>
    <div class="notice_to_share"><p>@Html.GetGlobalResource("OnlineWizard", "NoticeToShare")</p><p><img src="~/Content/images/social-add.png" /></p></div>

<div id="emBlockWz">
<h4>@Html.GetGlobalResource("OnlineWizard", "SendInvitations")</h4>
<label for ="emText">@Html.GetGlobalResource("OnlineWizard", "EnterMessageText")</label>
<textarea cols="40" rows="3"  class="em-add-text" id ="emText"></textarea>
<a href="#" class="em-add-link" onclick="return addline();">@Html.GetGlobalResource("OnlineWizard", "AddEMail")</a>
<table id="emTable"></table>
<input type="hidden" id ="count" name="count" value="0">
<a href="#" onclick="readyEmails('emTable'); return false;">@Html.GetGlobalResource("OnlineWizard", "SendToEmails")</a>
</div>
<div id = "emOkWz" class="emOkWz" style="display:none;">
    @Html.GetGlobalResource("OnlineWizard", "MessageSended")
    </div>
</form>